# -*- coding:utf-8 -*-
import requests
import pandas as pd
import os
import json
from pyecharts.charts import WordCloud
from pyecharts import options as opts
from datetime import date
pd.set_option('display.max_columns', None)
#显示所有行
pd.set_option('display.max_rows', None)

host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=tNOwsBxxGLDdEQMSfEzGMG2d&client_secret=D86atOA7FcBnQ8EqoCNAuHSBNl6i3suy'

response = requests.get(host)
if response:
    print(response.json()['access_token'])
access_token = '24.056093c304ac8a40c5cb958e70954477.2592000.1611450337.282335-23387464'
url_sentiment_classify = 'https://aip.baidubce.com/rpc/2.0/nlp/v1/sentiment_classify?charset=UTF-8&access_token=' +  access_token
print(url_sentiment_classify)
#按照要求设置请求头
headers = {'content-type': 'application/json'}

# 创建变量，写入需要分词的文本
st = "i don't like"

# 用requests工具包发送请求
response = requests.post(url_sentiment_classify,
                         data = json.dumps({'text': st}),    # st变量写在这里
                         headers = headers)
if response:
    result = response.json()
print(result)
